package ooday04;

public class PolymorphicDemo {
    public static void main(String[] args) {
        /*
        Dog zz=new Dog("仔仔",3,"黄");
        //zz.age/name/color/drink()/eat()/swim()/lookHome()
        Animal wc=new Dog("旺财",2,"黑");
        wc.drink();
        Swim ww=new Dog();
        ww.swim();
        */
        /*
        Master master=new Master();
        Dog dog=new Dog("仔仔",3,"黄");
        Chick chick=new Chick("旺财",2,"黑");
        Fish fish=new Fish("小金",1,"金");
        master.feed(dog);
        master.feed(chick);
        master.feed(fish);
         */
        Animal[] animal=new Animal[3];
        animal[0]=new Dog("旺财",2,"黑");
        animal[1]=new Chick("仔仔",3,"黄");
        animal[2]=new Fish("庄周",18,"蓝");
        for (int i=0;i< animal.length;i++){
            System.out.println(animal[i].name);
            animal[i].eat();
            animal[i].drink();
            if (animal[i] instanceof Dog){
                Dog dog=(Dog)animal[i];
                dog.LookHome();
            }
            if (animal[i] instanceof Chick){
                Chick chick=(Chick) animal[i];
                chick.LayEggs();
            }
            if (animal[i] instanceof Swim){
                Swim swim=(Swim) animal[i];
                swim.swim();

            }
        }
        /*
        Animal animal1=new Dog("仔仔",3,"黄");
        Dog d=(Dog) animal1;
        Swim s=(Swim) animal1;
        //Fish f=(Fish) animal1;
        System.out.println(animal1 instanceof Dog);
        System.out.println(animal1 instanceof Swim);
        System.out.println(animal1 instanceof Fish);
        if(animal1 instanceof Dog){
            Dog g=(Dog) animal1;
        }else {
            System.out.println("animal1不是Fish类型");
        }
         */
    }
}